package com.tmz.cloudmall.cloudmallproduct.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tmz.cloudmall.cloudmallproduct.domain.ProductAttr;
import com.tmz.cloudmall.cloudmallproduct.service.IProductAttrService;
import com.tmz.cloudmall.cloudmallcommon.common.annotation.Log;
import com.tmz.cloudmall.cloudmallcommon.common.core.controller.BaseController;
import com.tmz.cloudmall.cloudmallcommon.common.core.domain.AjaxResult;
import com.tmz.cloudmall.cloudmallcommon.common.core.page.TableDataInfo;
import com.tmz.cloudmall.cloudmallcommon.common.enums.BusinessType;
import com.tmz.cloudmall.cloudmallcommon.common.utils.poi.ExcelUtil;

/**
 * 商品属性Controller
 * 
 * @author tmz
 * @date 2025-08-16
 */
@RestController
@RequestMapping("/cloudmallproduct/productAttr")
public class ProductAttrController extends BaseController
{
    @Autowired
    private IProductAttrService productAttrService;

    /**
     * 查询商品属性列表
     */
    @PreAuthorize("@ss.hasPermi('cloudmallproduct:productAttr:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductAttr productAttr)
    {
        startPage();
        List<ProductAttr> list = productAttrService.selectProductAttrList(productAttr);
        return getDataTable(list);
    }

    /**
     * 导出商品属性列表
     */
    @PreAuthorize("@ss.hasPermi('cloudmallproduct:productAttr:export')")
    @Log(title = "商品属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductAttr productAttr)
    {
        List<ProductAttr> list = productAttrService.selectProductAttrList(productAttr);
        ExcelUtil<ProductAttr> util = new ExcelUtil<ProductAttr>(ProductAttr.class);
        util.exportExcel(response, list, "商品属性数据");
    }

    /**
     * 获取商品属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloudmallproduct:productAttr:query')")
    @GetMapping(value = "/{attrId}")
    public AjaxResult getInfo(@PathVariable("attrId") Long attrId)
    {
        return success(productAttrService.selectProductAttrByAttrId(attrId));
    }

    /**
     * 新增商品属性
     */
    @PreAuthorize("@ss.hasPermi('cloudmallproduct:productAttr:add')")
    @Log(title = "商品属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductAttr productAttr)
    {
        return toAjax(productAttrService.insertProductAttr(productAttr));
    }

    /**
     * 修改商品属性
     */
    @PreAuthorize("@ss.hasPermi('cloudmallproduct:productAttr:edit')")
    @Log(title = "商品属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductAttr productAttr)
    {
        return toAjax(productAttrService.updateProductAttr(productAttr));
    }

    /**
     * 删除商品属性
     */
    @PreAuthorize("@ss.hasPermi('cloudmallproduct:productAttr:remove')")
    @Log(title = "商品属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attrIds}")
    public AjaxResult remove(@PathVariable Long[] attrIds)
    {
        return toAjax(productAttrService.deleteProductAttrByAttrIds(attrIds));
    }
}
